$(function () {
    var goodsstore_id = parseInt(GetQueryString('goodsstore_id'));
    var html_data = {
        baseConfig: baseConfig,
        sessionid: '',
        sessionid_q: '',
        address_info: {},
        province_list: [],
        city_list: [],
        county_list: [],
        address_list: [],
        file_id:'',
        file_src:'',
        goods_info:{}

    };
    var app = new Vue({
        el: '#address_modefy',
        data: html_data,
        methods: {

            modefy_address: function () {
                var parm = {};
                if (html_data.goods_info.name) {
                    parm.name = html_data.goods_info.name;
                } else {
                    Magiclamp.mcAlert("提示", "代购店铺名称不能为空！");
                    return;
                }
                parm['files'] = html_data.file_id;
                if(html_data.lat){
                    parm['la'] = html_data.lat;
                    parm['lo'] = html_data.lng;
                }
                parm['desc'] = html_data.goods_info.desc;
                parm['address'] = html_data.goods_info.address;

                parm['is_out'] = html_data.goods_info.is_out;
                if (html_data.goods_info.id) {
                    parm['goodsstore_id'] = html_data.goods_info.id;

                    api.lgoods.update_goodsstore_by_buyer(parm).then(function (data) {
                        history.go(-1);
                    });
                }else{
                    api.lgoods.create_goodsstore_by_buyer(parm).then(function (data) {
                        history.go(-1);
                    });
                }
            },
            upload_image:function () {
                Magiclamp.mcConfirm("提示", "请在店铺门口拍照，系统将同时自动记录该店铺地址.", function () {

                }, function () {
                    ttjd.get_location_baidu(function (data) {
                        html_data.lat = data.lat;
                        html_data.lng = data.lng;
                    }, function (data) {

                    });
                    ttjd.get_take_photo_to_fileid(function (data) {
                        html_data.file_id = data["file_id"];
                        html_data.goods_info.small_image__fileurl = data["file_src"];
                    }, function (data) {
                        Magiclamp.mcAlert("提示", data);
                    });
                })


            },
            page_back: function () {
                baseConfig.page_back();
            }
        }
    });

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }

    if (goodsstore_id) {
        api.lgoods.get_goodsstroe({goodsstore_id: goodsstore_id}).then(function (data) {
            html_data.goods_info = data.result;
            html_data.goods_info.address_price = data.result.address_price / 100;


        });
    } else {
        html_data.goods_info = {name: '', desc: '', address: "", address_price:0, address_is_all:false, is_out:false};
    }


});
